import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
    private static boolean isInitialized = false;

    public static void main(String[] args) {
        System.out.println("=======东平县万东电影院管理系统=======");
        System.out.println("= 系统启动中...");
        initSystem();

        while (true) {
            showMainMenu();
            handleMainMenuInput();
        }
    }
    private static void initSystem() {
        if (isInitialized) {
            return;
        }
        if (UserList.getAllUsers().isEmpty()) {
            UserList.addUser(Admin.DEFAULT_ADMIN);
            System.out.println("= 已初始化默认管理员：admin，密码：ynuinfo#777");
        }
        List<Hall> halls = HallConfig.initHalls();
        System.out.println("= 已加载放映厅：" + halls.stream().map(Hall::getHallName).reduce((a, b) -> a + "、" + b).orElse("无"));
        Log.info("系统", "启动", "影院管理系统已成功启动");

        isInitialized = true;
        System.out.println("= 初始化完成，欢迎使用！\n");
    }
    private static void showMainMenu() {
        System.out.println("\n=======系统主菜单=======");
        System.out.println("1. 管理员登录");
        System.out.println("2. 经理登录");
        System.out.println("3. 前台登录");
        System.out.println("4. 退出系统");
        System.out.print("请选择操作（1-4）：");
    }
    private static void handleMainMenuInput() {
        Scanner scanner = new Scanner(System.in);
        int choice;
        try {
            choice = Integer.parseInt(scanner.next().trim());
        } catch (NumberFormatException e) {
            System.out.println("输入错误，请输入数字1-4！");
            return;
        }

        switch (choice) {
            case 1:
                Admin admin = new Admin("", "", "", "", "", "管理员");
                admin.login();
                break;
            case 2:
                Manager manager = new Manager("", "", "", "", "", "经理");
                manager.login();
                break;
            case 3:
                FrontDesk frontDesk = new FrontDesk("", "", "", "", "", "前台");
                frontDesk.login();
                break;
            case 4:
                Log.info("系统", "退出", "用户主动退出系统");
                System.out.println("感谢使用，再见！");
                System.exit(0);
                break;
            default:
                System.out.println("输入无效，请重新选择1-4！");
        }
    }
}